package cn.dakaqi.validator;

import javax.annotation.Resource;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import cn.dakaqi.annotation.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.MessageSource;


public class NotNUllValidator implements ConstraintValidator<NotNull, Object> {
    
    @Resource
    private MessageSource messageSource;
    
    private String field;
    
    public void initialize(NotNull parameters) {
        // Locale currentLocale = LocaleContextHolder.getLocale();
        this.field = parameters.field();
        // if (StringUtils.isNotBlank(field)) {
        // this.field = "information.field." + parameters.field();
        // this.field = messageSource.getMessage(this.field, null, currentLocale);
        // }
    }
    
    public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
        if (object instanceof String) {
            String str = (String) object;
            return object != null && StringUtils.isNotBlank(str);
        }
        return object != null;
    }
}